#include "queue.h"

int size(struct queue *que)
{
    return que->size;
}
int isempty(struct queue *que)
{
    return que->size==0;
}
struct queue *create_queue(void)
{

    struct queue *que = (struct queue*)malloc(sizeof(struct queue));
    que->size = 0;
    que->next = NULL;
    que->last = que;
    return que;
}
void push(struct queue_data *data, struct queue *que)
{
    struct queue *new_node = (struct queue *)malloc(sizeof(struct queue));
    memcpy(&new_node->data, data, sizeof(struct queue_data));
    new_node->next = NULL;
    que->size = que->size + 1;
    que->last->next = new_node;
    que->last = new_node;
}
struct queue_data front(struct queue *que)
{
    if(isempty(que))
    {
        printf("Queue is empty\n");
        return (struct queue_data){0};
    }
    return que->next->data;
}
void pop(struct queue *que)
{

    if (isempty(que))
    {
        printf("Queue is empty\n");
        return;
    }
    struct queue *temp = que->next;
    que->next = temp->next;
    free(temp);
    que->size = que->size - 1;
    if (isempty(que))
    {
        que->last = que;
    }
}
void destroy_queue(struct queue *que)
{
    while (!isempty(que))
    {
        pop(que);
    }
    free(que);
}
